package com.clientmanage.controller;

import com.clientmanage.domain.vo.serviceItemVo;
import com.clientmanage.domain.resp.PageResult;
import com.clientmanage.domain.resp.Result;
import com.clientmanage.service.IServiceItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 服务项目控制器
 * 实现服务项目设置相关接口
 */
@RestController
@RequestMapping("/service")
public class ServiceItemController {
    @Autowired
    private IServiceItemService serviceItemService;

    /**
     * 获取服务项目列表
     * 接口地址：GET /service/list
     */
    @GetMapping("/list")
    public Result<PageResult<serviceItemVo>> getServiceList(
        @RequestParam(required = false) String name,
        @RequestParam(required = false) String category,
        @RequestParam(required = false) Boolean enabled,
        @RequestParam(defaultValue = "1") int pageNum,
        @RequestParam(defaultValue = "10") int pageSize
    ) {
        return Result.success(serviceItemService.pageQuery(name, category, enabled, pageNum, pageSize));
    }

    /**
     * 新增服务项目
     * 接口地址：POST /service/add
     */
    @PostMapping("/add")
    public Result<Void> addService(@RequestBody serviceItemVo vo) {
        serviceItemService.saveOrUpdateServiceItem(vo);
        return Result.success();
    }

    /**
     * 更新服务项目
     * 接口地址：PUT /service/update
     */
    @PutMapping("/update")
    public Result<Void> updateService(@RequestBody serviceItemVo vo) {
        serviceItemService.saveOrUpdateServiceItem(vo);
        return Result.success();
    }

    /**
     * 删除服务项目
     * 接口地址：DELETE /service/delete/{id}
     */
    @DeleteMapping("/delete/{id}")
    public Result<Void> deleteService(@PathVariable String id) {
        serviceItemService.deleteById(id);
        return Result.success();
    }
}
